<?php

!defined('IN_APP') && exit('Access Denied');

class eventmodel extends modelbase {

	 public function __toString() {
	       // return $this->foo;
	}


    function get_by_id($id) {
        $event = $this->collection->findOne(array("id" => $id));
        $event['format_starttime'] = tdate($event['starttime']);
        $event['format_endtime'] = tdate($event['endtime']);
        $event['remainnum'] = $event['membernum'] - $event['follownum'] ;
        $event['detail']=tstripslashes( $event['detail'] );
        return $event;
    }

    function get_list( $query = array() ) {
        $eventlist = array();
        $cursor = $this->collection->find($query)->sort(array('id'=>-1)); 
        foreach ($cursor as $event){
		  $event['format_starttime'] = tdate($event['starttime']);
	        $event['format_endtime'] = tdate($event['endtime']);
	        $event['remainnum'] = $event['membernum'] - $event['follownum'] ;
	        $event['detail']=tstripslashes( $event['detail'] );
              $eventlist[] = $event;
        }
        return $eventlist;
    }
    
    /**
    function get_list1() {
        $eventlist = array();
        $cursor = $this->collection->find(); 
        while ($cursor->hasNext()){
        	$event = $cursor->getNext(); 
            //$event['lastlogintime'] = tdate($event['lastlogin']);
            $eventlist[] = $event;
        }
        return $eventlist;
    }*/

 
    /* 添加用户，本函数需要返回uid */

    function add($event) {
		$id=$this->get_autoincre_id('event');
		$event['id'] = $id;
		$event['dateline'] = $this->base->time;
		$event['follownum'] = 0;
		$this->collection->insert($event); 
		return $id;
    }

    function remove($ids) {
    	$criteria=array(
    		'id'=> array('$in'=>$ids)
    	);
    	$this->collection->remove($criteria);
     }

     function update($id, $set) {
        $this->collection->update(array("id" => $id),array('$set' => $set) ); 
    }

   

  

}

